﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp6
{
    class Program
    {
        static void Main(string[] args)
        {
            SortedList sortedList = new SortedList();
            sortedList.Add(1,"张作霖");
            sortedList.Add(2, "张学良");
            sortedList.Add(3, "蒋介石");
            sortedList.Add(4, "杨虎城");
            sortedList.Add(5, "江青");
            sortedList.Add(6, "林彪");
            Console.WriteLine("请输入人物编号 1~6");
            int id = int.Parse(Console.ReadLine());
            bool flag = sortedList.ContainsKey(id);
            if (flag)
            {
                string name = sortedList[id].ToString();
                Console.WriteLine("你查询的人物是{0}",name);
            }
            else
            {
                Console.WriteLine("你的输入有误");
            }
            Console.WriteLine("全部信息如下");
            foreach (DictionaryEntry item in sortedList)
            {
                int id2 = (int)item.Key;
                string value=item.Value.ToString();
                Console.WriteLine("编号{0}，名字{1}",id2,value);
            }
            Console.ReadKey();
        }
    }
}
